package org.jiuling.aliyun.config;

import org.jiuling.aliyun.config.exception.AliYunConfigRuntimeException;
import org.jiuling.basics.validation.StringVerify;

/**
 * 阿里云配置
 * @author 紫灵
 * @date 2023年01月03日 21时05分21秒
 */
public class AliYunConfig {

    /** 密钥id */
    private String accessKeyId;
    /** 密钥 */
    private String accessKeySecret;

    public String getAccessKeyId() {
        return accessKeyId;
    }

    public void setAccessKeyId(String accessKeyId) {
        this.accessKeyId = accessKeyId;
    }

    public String getAccessKeySecret() {
        return accessKeySecret;
    }

    public void setAccessKeySecret(String accessKeySecret) {
        this.accessKeySecret = accessKeySecret;
    }

    /**
     * 建造者
     * @return 建造者
     */
    public static Builder builder(){
        return new Builder();
    }

    /** 建造着 */
    public static class Builder{
        private final AliYunConfig aliYunConfig;

        /** 无参构造方法 */
        public Builder(){
            aliYunConfig = new AliYunConfig();
        }

        /**
         * 添加密钥id
         * @param accessKeyId 密钥id
         * @return 建造者对象
         */
        public Builder addAccessKeyId(String accessKeyId){
            aliYunConfig.accessKeyId = accessKeyId;
            return this;
        }

        /**
         * 添加密钥
         * @param accessKeySecret 密钥
         * @return 建造者对象
         */
        public Builder addAccessKeySecret(String accessKeySecret){
            aliYunConfig.accessKeySecret = accessKeySecret;
            return this;
        }

        /**
         * 构建
         * @return 阿里云配置
         */
        public AliYunConfig build(){
            if(StringVerify.isBlank(aliYunConfig.accessKeyId)){
                throw new AliYunConfigRuntimeException("密钥id不能为空！");
            }
            if(StringVerify.isBlank(aliYunConfig.accessKeySecret)){
                throw new AliYunConfigRuntimeException("密钥不能为空！");
            }
            return aliYunConfig;
        }
    }
}
